<template>
<div>
    <h2 class="sub-header">Add Hero</h2>
    <form>
        <div class="form-group">
            <label for="exampleInputEmail1">名字</label>
            <input type="text" class="form-control" id="exampleInputEmail1"
             placeholder="名字"
             v-model="formdata.name">
          </div>
            <div class="form-group">
                <label for="exampleInputPassword1">性别</label>
                <input type="text" class="form-control" id="exampleInputPassword1"
                placeholder="性别"
                v-model="formdata.gender">
          </div>

          <button type="submit" class="btn btn-success" @click.prevent="addHero()">
            Submit</button>
    </form>
</div>
</template>

<script>
// import axios from 'axios'

export default {
  data() {
    return {
      formdata: {
        name: '',
        gender: ''
      }
    }
  },
  methods: {
    addHero() {
      // 获取要添加的数据 this.formdata
      // axios.post(url,this.formdata)
      // 回到list页
      // this.axios.get()
      this.$http.post('heroes', this.formdata).then(res => {
        const { status, data } = res
        if (status === 201) {
          //
          this.$router.push('/list')
        }
      })
    }
  }
}
</script>

<style>
</style>
